//Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Collections.Generic;
using System.Text;

namespace Eas.WebCrawler.PlugIns.TemporaryStorage {
    /// <summary>A base class for implementations of <see cref="Eas.WebCrawler.Interfaces.TemporaryStorage"/> that stores data in some sort of stream.</summary>
    public abstract class StreamBasedStorage : Eas.WebCrawler.Common.BaseDisposable, Eas.WebCrawler.Interfaces.TemporaryStorage{

        /// <summary>Disposes of the current object.</summary>
        /// <param name="isDisposing">Whether the class is being disposed or finalized.</param>
        protected override void Dispose(bool isDisposing) {
            base.Dispose(isDisposing);
        }

        #region TemporaryStorage Members
        /// <summary>Provides a <see cref="System.IO.TextReader"/> for reading contents stored in this store.</summary>
        /// <returns>A <see cref="System.IO.TextReader"/> for reading contents stored in this store.</returns>
        public System.IO.TextReader GetTextReader() {
            return new System.IO.StreamReader(GetStreamForReading());
        }

        /// <summary>Provides a <see cref="System.IO.TextWriter"/> for writing contents into this store.</summary>
        /// <returns>A <see cref="System.IO.TextWriter"/> for writing contents into this store.</returns>
        public System.IO.TextWriter GetTextWriter() {
            return new System.IO.StreamWriter(GetStreamForWriting());
        }

        /// <summary>Provides a <see cref="System.IO.BinaryReader"/> for reading contents stored in this store.</summary>
        /// <returns>A <see cref="System.IO.BinaryReader"/> for reading contents stored in this store.</returns>
        public System.IO.BinaryReader GetBinaryReader() {
            return new System.IO.BinaryReader(GetStreamForReading());
        }

        /// <summary>Provides a <see cref="System.IO.BinaryWriter"/> for writing contents into this store.</summary>
        /// <returns>A <see cref="System.IO.BinaryWriter"/> for writing contents into this store.</returns>
        public System.IO.BinaryWriter GetBinaryWriter() {
            return new System.IO.BinaryWriter(GetStreamForWriting());
        }

        #endregion
        /// <summary>Implemented in derived classes to get the stream used for reading.</summary>
        /// <returns>The stream used for reading.</returns>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
        protected abstract System.IO.Stream GetStreamForReading();
        /// <summary>Implemented in derived classes to get the stream used for writting.</summary>
        /// <returns>The stream used for writting.</returns>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
        protected abstract System.IO.Stream GetStreamForWriting();
    }
}
